<!DOCTYPE html>
<html lang="zh-CN">
<head>
  <meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=2">
<meta name="theme-color" content="#222">
<meta name="generator" content="Hexo 5.2.0">


  <link rel="apple-touch-icon" sizes="180x180" href="/murmur/images/apple-touch-icon-next.png">
  <link rel="icon" type="image/png" sizes="32x32" href="/murmur/images/favicon-32x32-next.png">
  <link rel="icon" type="image/png" sizes="16x16" href="/murmur/images/favicon-16x16-next.png">
  <link rel="mask-icon" href="/murmur/images/logo.svg" color="#222">

<link rel="stylesheet" href="/murmur/css/main.css">



<link rel="stylesheet" href="//cdn.jsdelivr.net/npm/@fortawesome/fontawesome-free@5.15.1/css/all.min.css">
  <link rel="stylesheet" href="//cdn.jsdelivr.net/npm/animate.css@3.1.1/animate.min.css">
  <link rel="stylesheet" href="//cdn.jsdelivr.net/npm/nprogress@0.2.0/nprogress.css">
  <script src="//cdn.jsdelivr.net/npm/nprogress@0.2.0/nprogress.js"></script>

<script class="hexo-configurations">
    var NexT = window.NexT || {};
    var CONFIG = {"hostname":"gitee.com","root":"/murmur/","scheme":"Gemini","version":"8.0.2","exturl":false,"sidebar":{"position":"left","display":"post","padding":18,"offset":12},"copycode":true,"bookmark":{"enable":false,"color":"#222","save":"auto"},"fancybox":false,"mediumzoom":false,"lazyload":false,"pangu":false,"comments":{"style":"tabs","active":"disqus","storage":true,"lazyload":false,"nav":null},"motion":{"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"fadeInDown","post_body":"fadeInDown","coll_header":"fadeInLeft","sidebar":"fadeInUp"}},"prism":false,"i18n":{"placeholder":"搜索...","empty":"没有找到任何搜索结果：${query}","hits_time":"找到 ${hits} 个搜索结果（用时 ${time} 毫秒）","hits":"找到 ${hits} 个搜索结果"}};
  </script>

  <meta name="description" content="变量的声明、变量的作用域；良好的编程风格；基本数据类型与复合数据类型；表达式运算符；表达式转换和优先级">
<meta property="og:type" content="article">
<meta property="og:title" content="计应本的自考笔记(2)-Java数据与表达式">
<meta property="og:url" content="https://gitee.com/lianghuilin/murmur.git/university_notes/Java(2)-%E6%95%B0%E6%8D%AE%E4%B8%8E%E8%A1%A8%E8%BE%BE%E5%BC%8F/index.html">
<meta property="og:site_name" content="汇话板">
<meta property="og:description" content="变量的声明、变量的作用域；良好的编程风格；基本数据类型与复合数据类型；表达式运算符；表达式转换和优先级">
<meta property="og:locale" content="zh_CN">
<meta property="og:image" content="https://gitee.com/lianghuilin/blog-image-warehouse/raw/master/094e5c06c38b31fef426c9ac8c033f6.jpg">
<meta property="og:image" content="https://gitee.com/lianghuilin/blog-image-warehouse/raw/master/79eb368db9b657045fe2cd6734542f9.jpg">
<meta property="article:published_time" content="2022-02-19T05:30:12.000Z">
<meta property="article:modified_time" content="2022-03-03T15:05:37.022Z">
<meta property="article:author" content="William Leung">
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="https://gitee.com/lianghuilin/blog-image-warehouse/raw/master/094e5c06c38b31fef426c9ac8c033f6.jpg">


<link rel="canonical" href="https://gitee.com/lianghuilin/murmur.git/university_notes/Java(2)-%E6%95%B0%E6%8D%AE%E4%B8%8E%E8%A1%A8%E8%BE%BE%E5%BC%8F/">


<script class="page-configurations">
  // https://hexo.io/docs/variables.html
  CONFIG.page = {
    sidebar: "",
    isHome : false,
    isPost : true,
    lang   : 'zh-CN'
  };
</script>

  <title>计应本的自考笔记(2)-Java数据与表达式 | 汇话板</title>
  


  <script>
    var _hmt = _hmt || [];
    (function() {
      var hm = document.createElement("script");
      hm.src = "https://hm.baidu.com/hm.js?a49081c570a782a242cdf6e19e1a584d";
      var s = document.getElementsByTagName("script")[0];
      s.parentNode.insertBefore(hm, s);
    })();
  </script>




  <noscript>
  <style>
  body { margin-top: 2rem; }

  .use-motion .menu-item,
  .use-motion .sidebar,
  .use-motion .post-block,
  .use-motion .pagination,
  .use-motion .comments,
  .use-motion .post-header,
  .use-motion .post-body,
  .use-motion .collection-header {
    visibility: visible;
  }

  .use-motion .header,
  .use-motion .site-brand-container .toggle,
  .use-motion .footer { opacity: initial; }

  .use-motion .site-title,
  .use-motion .site-subtitle,
  .use-motion .custom-logo-image {
    opacity: initial;
    top: initial;
  }

  .use-motion .logo-line {
    transform: scaleX(1);
  }

  .search-pop-overlay, .sidebar-nav { display: none; }
  .sidebar-panel { display: block; }
  </style>
</noscript>

</head>

<body itemscope itemtype="http://schema.org/WebPage" class="use-motion">
  <div class="headband"></div>

  <main class="main">
    <header class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-container">
  <div class="site-nav-toggle">
    <div class="toggle" aria-label="切换导航栏">
        <span class="toggle-line"></span>
        <span class="toggle-line"></span>
        <span class="toggle-line"></span>
    </div>
  </div>

  <div class="site-meta">

    <a href="/murmur/" class="brand" rel="start">
      <i class="logo-line"></i>
      <h1 class="site-title">汇话板</h1>
      <i class="logo-line"></i>
    </a>
      <p class="site-subtitle" itemprop="description">设定目标，放慢步调，用温和的力量自我改革</p>
  </div>

  <div class="site-nav-right">
    <div class="toggle popup-trigger">
    </div>
  </div>
</div>



<nav class="site-nav">
  <ul class="main-menu menu">
        <li class="menu-item menu-item-home">

    <a href="/murmur/" rel="section"><i class="fa fa-home fa-fw"></i>首页</a>

  </li>
        <li class="menu-item menu-item-categories">

    <a href="/murmur/categories/" rel="section"><i class="fa fa-th fa-fw"></i>分类</a>

  </li>
  </ul>
</nav>




</div>
        
  
  <div class="toggle sidebar-toggle">
    <span class="toggle-line"></span>
    <span class="toggle-line"></span>
    <span class="toggle-line"></span>
  </div>

  <aside class="sidebar">

    <div class="sidebar-inner sidebar-nav-active sidebar-toc-active">
      <ul class="sidebar-nav">
        <li class="sidebar-nav-toc">
          文章目录
        </li>
        <li class="sidebar-nav-overview">
          站点概览
        </li>
      </ul>

      <div class="sidebar-panel-container">
        <!--noindex-->
        <section class="post-toc-wrap sidebar-panel">
            <div class="post-toc animated"><ol class="nav"><li class="nav-item nav-level-2"><a class="nav-link" href="#%E4%B8%BB%E8%A6%81%E7%AC%94%E8%AE%B0"><span class="nav-number">1.</span> <span class="nav-text">主要笔记</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#%E5%9F%BA%E7%A1%80%E8%AF%AD%E6%B3%95"><span class="nav-number">1.1.</span> <span class="nav-text">基础语法</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#%E8%AF%AD%E6%B3%95%E5%85%83%E7%B4%A0"><span class="nav-number">1.1.1.</span> <span class="nav-text">语法元素</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#%E5%85%B3%E9%94%AE%E5%AD%97"><span class="nav-number">1.1.2.</span> <span class="nav-text">关键字</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#%E6%A0%87%E8%AF%86%E7%AC%A6%E4%B8%8E%E5%91%BD%E5%90%8D"><span class="nav-number">1.1.3.</span> <span class="nav-text">标识符与命名</span></a></li></ol></li><li class="nav-item nav-level-3"><a class="nav-link" href="#%E6%95%B0%E6%8D%AE%E7%B1%BB%E5%9E%8B"><span class="nav-number">1.2.</span> <span class="nav-text">数据类型</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#%E5%9F%BA%E7%A1%80%E6%95%B0%E6%8D%AE%E7%B1%BB%E5%9E%8B"><span class="nav-number">1.2.1.</span> <span class="nav-text">基础数据类型</span></a><ol class="nav-child"><li class="nav-item nav-level-5"><a class="nav-link" href="#%E6%95%B4%E6%95%B0%E7%B1%BB%E5%9E%8B%EF%BC%9Abyte%E3%80%81short%E3%80%81int%E3%80%81long"><span class="nav-number">1.2.1.1.</span> <span class="nav-text">整数类型：byte、short、int、long</span></a></li><li class="nav-item nav-level-5"><a class="nav-link" href="#%E6%B5%AE%E7%82%B9%E6%95%B0%E7%B1%BB%E5%9E%8B%EF%BC%9Afloat%E3%80%81double"><span class="nav-number">1.2.1.2.</span> <span class="nav-text">浮点数类型：float、double</span></a></li><li class="nav-item nav-level-5"><a class="nav-link" href="#%E5%AD%97%E7%AC%A6%E4%B8%B2%E7%B1%BB%E5%9E%8B%EF%BC%9Achar"><span class="nav-number">1.2.1.3.</span> <span class="nav-text">字符串类型：char</span></a></li><li class="nav-item nav-level-5"><a class="nav-link" href="#%E5%B8%83%E5%B0%94%E7%B1%BB%E5%9E%8B%EF%BC%9Aboolean"><span class="nav-number">1.2.1.4.</span> <span class="nav-text">布尔类型：boolean</span></a></li></ol></li><li class="nav-item nav-level-4"><a class="nav-link" href="#%E5%A4%8D%E5%90%88%E6%95%B0%E6%8D%AE%E7%B1%BB%E5%9E%8B"><span class="nav-number">1.2.2.</span> <span class="nav-text">复合数据类型</span></a></li></ol></li><li class="nav-item nav-level-3"><a class="nav-link" href="#%E8%A1%A8%E8%BE%BE%E5%BC%8F"><span class="nav-number">1.3.</span> <span class="nav-text">表达式</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#%E8%BF%90%E7%AE%97%E7%AC%A6"><span class="nav-number">1.4.</span> <span class="nav-text">运算符</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#%E7%BB%83%E4%B9%A0%E9%A2%98"><span class="nav-number">2.</span> <span class="nav-text">练习题</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#%E9%80%89%E6%8B%A9%E9%A2%98"><span class="nav-number">2.1.</span> <span class="nav-text">选择题</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#%E5%A1%AB%E7%A9%BA%E9%A2%98"><span class="nav-number">2.2.</span> <span class="nav-text">填空题</span></a></li></ol></li></ol></div>
        </section>
        <!--/noindex-->

        <section class="site-overview-wrap sidebar-panel">
          <div class="site-author site-overview-item animated" itemprop="author" itemscope itemtype="http://schema.org/Person">
  <p class="site-author-name" itemprop="name">William Leung</p>
  <div class="site-description" itemprop="description"></div>
</div>
<div class="site-state-wrap site-overview-item animated">
  <nav class="site-state">
      <div class="site-state-item site-state-posts">
          <a href="/murmur/archives">
          <span class="site-state-item-count">43</span>
          <span class="site-state-item-name">文章</span>
        </a>
      </div>
      <div class="site-state-item site-state-categories">
            <a href="/murmur/categories/">
          
        <span class="site-state-item-count">9</span>
        <span class="site-state-item-name">分类</span></a>
      </div>
      <div class="site-state-item site-state-tags">
            <a href="/murmur/tags/">
        <span class="site-state-item-count">1</span>
        <span class="site-state-item-name">标签</span></a>
      </div>
  </nav>
</div>



        </section>
      </div>
    </div>
  </aside>
  <div class="sidebar-dimmer"></div>


    </header>

    
  <div class="back-to-top">
    <i class="fa fa-arrow-up"></i>
    <span>0%</span>
  </div>

<noscript>
  <div class="noscript-warning">Theme NexT works best with JavaScript enabled</div>
</noscript>


    <div class="main-inner post posts-expand">
      

      

  


<div class="post-block">
  
  

  <article itemscope itemtype="http://schema.org/Article" class="post-content" lang="zh-CN">
    <link itemprop="mainEntityOfPage" href="https://gitee.com/lianghuilin/murmur.git/university_notes/Java(2)-%E6%95%B0%E6%8D%AE%E4%B8%8E%E8%A1%A8%E8%BE%BE%E5%BC%8F/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/murmur/images/avatar.gif">
      <meta itemprop="name" content="William Leung">
      <meta itemprop="description" content="">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="汇话板">
    </span>
      <header class="post-header">
        <h1 class="post-title" itemprop="name headline">
          计应本的自考笔记(2)-Java数据与表达式
        </h1>

        <div class="post-meta-container">
          <div class="post-meta">
    <span class="post-meta-item">
      <span class="post-meta-item-icon">
        <i class="far fa-calendar"></i>
      </span>
      <span class="post-meta-item-text">发表于</span>

      <time title="创建时间：2022-02-19 13:30:12" itemprop="dateCreated datePublished" datetime="2022-02-19T13:30:12+08:00">2022-02-19</time>
    </span>
      <span class="post-meta-item">
        <span class="post-meta-item-icon">
          <i class="far fa-calendar-check"></i>
        </span>
        <span class="post-meta-item-text">更新于</span>
        <time title="修改时间：2022-03-03 23:05:37" itemprop="dateModified" datetime="2022-03-03T23:05:37+08:00">2022-03-03</time>
      </span>
    <span class="post-meta-item">
      <span class="post-meta-item-icon">
        <i class="far fa-folder"></i>
      </span>
      <span class="post-meta-item-text">分类于</span>
        <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
          <a href="/murmur/categories/%E8%AE%A1%E5%BA%94%E6%9C%AC%E7%9A%84%E8%87%AA%E8%80%83%E7%AC%94%E8%AE%B0/" itemprop="url" rel="index"><span itemprop="name">计应本的自考笔记</span></a>
        </span>
    </span>

  
    <span class="post-meta-item" title="本文字数">
      <span class="post-meta-item-icon">
        <i class="far fa-file-word"></i>
      </span>
      <span class="post-meta-item-text">本文字数：</span>
      <span>3k</span>
    </span>
    <span class="post-meta-item" title="阅读时长">
      <span class="post-meta-item-icon">
        <i class="far fa-clock"></i>
      </span>
      <span class="post-meta-item-text">阅读时长 &asymp;</span>
      <span>3 分钟</span>
    </span>
</div>

            <div class="post-description">变量的声明、变量的作用域；良好的编程风格；基本数据类型与复合数据类型；表达式运算符；表达式转换和优先级</div>
        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">
        <h2 id="主要笔记"><a href="#主要笔记" class="headerlink" title="主要笔记"></a>主要笔记</h2><h3 id="基础语法"><a href="#基础语法" class="headerlink" title="基础语法"></a>基础语法</h3><h4 id="语法元素"><a href="#语法元素" class="headerlink" title="语法元素"></a>语法元素</h4><ul>
<li><p>艺术讲究留白，程序同样如此。换行符以及回车符都可以表示一行代码的结束，它们都被视为空白。除此之外，还有空格键、Tab键也是空白。我们在Java代码中应适当加入空白，以提高代码的易读性，你不用担心影响Java的执行，编译器会自动忽略掉这些空白。</p>
</li>
<li><p>代码注释对程序的易读性同样重要，并且编译器也会忽略注释。</p>
</li>
<li><p>Java代码的3种注释方式：</p>
<ol>
<li><p>行尾注释，对声明的变量，单行程序做简短说明；</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">private</span> Boolean show = <span class="keyword">true</span>; <span class="comment">// 是否显示</span></span><br></pre></td></tr></table></figure>
</li>
<li><p>独立注释，对方法的功能，设计逻辑及基本思想做说明注释；</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">/*  名称 */</span></span><br><span class="line"><span class="keyword">public</span> String name = <span class="string">&#x27;huilin&#x27;</span>;</span><br></pre></td></tr></table></figure>
</li>
<li><p>文档注释，写在公有类定义或公有方法头作为注释；</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">/*</span></span><br><span class="line"><span class="comment"> * 这是一个类</span></span><br><span class="line"><span class="comment"> */</span></span><br><span class="line"> <span class="keyword">public</span> <span class="class"><span class="keyword">class</span> <span class="title">HelloWorldApp</span> </span>&#123;</span><br><span class="line">     <span class="function"><span class="keyword">public</span> <span class="keyword">static</span> <span class="keyword">void</span> <span class="title">main</span><span class="params">()</span></span>&#123;</span><br><span class="line">         System.out.println(<span class="string">&quot;say hello&quot;</span>);</span><br><span class="line">     &#125;</span><br><span class="line"> &#125;</span><br></pre></td></tr></table></figure>
</li>
</ol>
</li>
<li><p>语句是Java最小的执行单位，语句以分号结尾。一个语句可以写连续的若干行。由{}包含的称为语句块。语句块可以嵌套声明。</p>
</li>
</ul>
<h4 id="关键字"><a href="#关键字" class="headerlink" title="关键字"></a>关键字</h4><ul>
<li>关键字也称为保留字，编译器预先保留用作特殊意义和用途的，所以不能作为标识符使用。</li>
</ul>
<figure class="highlight js"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">abstract、boolean、<span class="keyword">break</span>、byte、<span class="keyword">case</span>、cast、<span class="keyword">catch</span>、char、<span class="class"><span class="keyword">class</span>、<span class="title">const</span>、<span class="title">continue</span>、<span class="title">default</span>、<span class="title">do</span>、<span class="title">double</span>、<span class="title">else</span>、<span class="keyword">extends</span>、<span class="title">false</span>、<span class="title">final</span>、<span class="title">finally</span>、<span class="title">float</span>、<span class="title">for</span>、<span class="title">futrue</span>、<span class="title">generic</span>、<span class="title">goto</span>、<span class="title">if</span>、<span class="title">implements</span>、<span class="title">import</span>、<span class="title">inner</span>、<span class="title">instanceof</span>、<span class="title">int</span>、<span class="title">interface</span>、<span class="title">long</span>、<span class="title">native</span>、<span class="title">new</span>、<span class="title">null</span>、<span class="title">operator</span>、<span class="title">outer</span>、<span class="title">package</span>、<span class="title">private</span>、<span class="title">protected</span>、<span class="title">public</span>、<span class="title">rest</span>、<span class="title">return</span>、<span class="title">short</span>、<span class="title">static</span>、<span class="title">strictfp</span>、<span class="title">super</span>、<span class="title">switch</span>、<span class="title">synchronized</span>、<span class="title">this</span>、<span class="title">throw</span>、<span class="title">throws</span>、<span class="title">transient</span>、<span class="title">true</span>、<span class="title">try</span>、<span class="title">var</span>、<span class="title">void</span>、<span class="title">volatile</span>、<span class="title">while</span></span></span><br></pre></td></tr></table></figure>

<h4 id="标识符与命名"><a href="#标识符与命名" class="headerlink" title="标识符与命名"></a>标识符与命名</h4><ul>
<li>标识符由字母、数字、下划线或美元符组成的字符串。标识符区分大小写，长度没有限制。</li>
<li>标识符不能 以数字作为开头。标识符中不能含有特殊字符。</li>
<li>标识符可用作变量名、方法名、接口名和类名等。</li>
<li>Java源代码使用的是Unicode码，用16位无符号二进制数表示一个字符。</li>
<li>良好的编程风格：<ul>
<li>类名或接口名：名词，单词首字母大写，如<code>HelloWorld、Customer、SortClass</code>等；</li>
<li>方法名：动词，首字母小写的驼峰命名，如<code>getName、setAddress、searchKey</code>等；</li>
<li>变量名：全部为大写字母，如<code>BLUE_COLOR</code>；</li>
<li>变量名：包括所有实例变量、类变量、终极变量和静态变量，都应该首字母小写的驼峰命名，尽量不要使用下划线。如<code>balance、orders、byPercent</code>；</li>
</ul>
</li>
</ul>
<h3 id="数据类型"><a href="#数据类型" class="headerlink" title="数据类型"></a>数据类型</h3><h4 id="基础数据类型"><a href="#基础数据类型" class="headerlink" title="基础数据类型"></a>基础数据类型</h4><h5 id="整数类型：byte、short、int、long"><a href="#整数类型：byte、short、int、long" class="headerlink" title="整数类型：byte、short、int、long"></a>整数类型：byte、short、int、long</h5><ul>
<li>整数类型数据可存储十进制（1-9开头）、八进制（0开头）或者十六进制（0x开头）形式的数值</li>
<li>Integer.MAX_VALUE表示int类型的最大值，Integer.MIN_VALUE表示int类型的最小值</li>
<li>Long.MAX_VALUE表示long类型的最大值，Long.MIN_VALUE表示long类型的最小值</li>
</ul>
<h5 id="浮点数类型：float、double"><a href="#浮点数类型：float、double" class="headerlink" title="浮点数类型：float、double"></a>浮点数类型：float、double</h5><ul>
<li>单精度浮点型数据用float说明，双精度浮点型数据用double表示</li>
<li>浮点型常量默认情况下是double类型，除非用字母F明确是float类型</li>
</ul>
<h5 id="字符串类型：char"><a href="#字符串类型：char" class="headerlink" title="字符串类型：char"></a>字符串类型：char</h5><ul>
<li>单个字符用char类型表示，char类型的常量通常用一对单引号包含</li>
<li>字符串分为普通字符串和转义字符串</li>
</ul>
<h5 id="布尔类型：boolean"><a href="#布尔类型：boolean" class="headerlink" title="布尔类型：boolean"></a>布尔类型：boolean</h5><ul>
<li>布尔类型数据只有两个状态，true/false</li>
<li>Java是强类型语言，不允许数值类型和布尔类型相互转换</li>
</ul>
<h4 id="复合数据类型"><a href="#复合数据类型" class="headerlink" title="复合数据类型"></a>复合数据类型</h4><ul>
<li>复合类型数据包含数组、类和接口</li>
</ul>
<h3 id="表达式"><a href="#表达式" class="headerlink" title="表达式"></a>表达式</h3><ul>
<li>表达式由“运算符”和“操作数”组成。操作数通常是常量或者变量。运算符按功能可分为：算数运算符、关系运算符、逻辑运算符、位运算符、赋值运算符和条件运算符</li>
<li>变量是存储数据的基本单位，变量在使用前要先声明。</li>
<li>声明变量在方法内，称为自动变量、局部变量或者栈变量。也可以声明在类当中，称为类的成员变量。</li>
<li>简单数据类型的变量在声明后，自动分配内存空间；而创建一个对象引用后，需要使用new运算符实例化后，才会分配内存空间。</li>
<li>变量的作用域，是指可访问该变量的代码范围。类的成员变量作用域是整个类，方法的局部变量作用域是整个语句块。</li>
<li>如果类中的方法，存在同名变量，则会被方法内的变量屏蔽。</li>
</ul>
<h3 id="运算符"><a href="#运算符" class="headerlink" title="运算符"></a>运算符</h3><ul>
<li>算术运算符：加<code>+</code>、减<code>-</code>、乘<code>*</code>、除<code>/</code>、取模<code>%</code></li>
<li>算术运算符还有<code>++</code>自加1操作、<code>--</code>自减1操作。自加自减运算符前缀和后缀形势含义是不同的，<code>++i</code>是i先+1然后返回值，<code>i--</code>是先-1再返回值。</li>
<li>关系运算符用来比较两个值：大于<code>&gt;</code>、大于等于<code>&gt;=</code>、小于<code>&lt;</code>、小于等于<code>&lt;=</code>、等于<code>==</code>和不等于<code>!=</code></li>
<li>逻辑运算符：逻辑与<code>&amp;&amp;</code>、逻辑或<code>||</code>、逻辑非<code>!</code>，<code>&amp;&amp;</code>与<code>||</code>提供短路操作</li>
<li>位运算用来对二进制数据进行操作，包含：按位取反<code>~</code>、按位与<code>&amp;</code>、按位或<code>|</code>、异或<code>^</code>、右移<code>&gt;&gt;</code>、左移<code>&lt;&lt;</code>和无符右移<code>&gt;&gt;&gt;</code></li>
<li>此外，Java中还有扩展运算符<code>+=</code>、<code>-=</code>、<code>*=</code>、<code>/=</code>、<code>%=</code>、<code>&amp;=</code>、<code>|=</code>、<code>^=</code>、<code>&gt;&gt;=</code>、<code>&lt;&lt;=</code>、<code>&gt;&gt;&gt;=</code>，条件运算符<code>?:</code>、点运算符<code>.</code>、实例运算符<code>instanceof</code>、new运算符以及数组下标运算符<code>[]</code></li>
<li>Java是一种强类型语言，不支持自动的隐式类型转换，必须显式的进行类型转换，目的是保证转换时不丢失有用信息。但低级类型可以转换高级类型。</li>
<li>运算符的优先级：<br><img src="https://gitee.com/lianghuilin/blog-image-warehouse/raw/master/094e5c06c38b31fef426c9ac8c033f6.jpg"><br><img src="https://gitee.com/lianghuilin/blog-image-warehouse/raw/master/79eb368db9b657045fe2cd6734542f9.jpg"></li>
</ul>
<h2 id="练习题"><a href="#练习题" class="headerlink" title="练习题"></a>练习题</h2><h3 id="选择题"><a href="#选择题" class="headerlink" title="选择题"></a>选择题</h3><ol>
<li>以下，Java关键字是【switch、new、long】</li>
<li>以下，能作为Java程序中标识符的是【Val】</li>
<li>能作为Java程序变量名的是【CASE】</li>
<li>能作为Java语言注释的是【从//开始知道行尾】</li>
<li>main标识符不能作为【主函数名】</li>
<li>属于Java基本数据类型的是【整型、浮点型、布尔型】</li>
<li>以下类型转换中必须进行强制类型转换的是【long→char】</li>
<li>以下类型转换中必须进行强制类型转换的是【long→byte】</li>
<li>以下属于转义字符串的是【\t、\141、\u0061】</li>
</ol>
<h3 id="填空题"><a href="#填空题" class="headerlink" title="填空题"></a>填空题</h3><ol>
<li>用来声明Java布尔类型的保留字是【boolean】</li>
<li>方法内定义的变量称为【局部变量、自动变量、临时变量或者栈变量】</li>
<li>Java逻辑与和逻辑或运算符有一个特殊功能，当左侧操作数能决定表达式的值时，跳过右侧操作数的运算，称为【短路操作】</li>
<li>一个byte类型的运算数和一个int类型的运算数进行运算，结果的类型是【int】</li>
<li>当不同类型的数据进行运算时，表示范围小的类型转换成表示范围大的类型，称为【自动类型转换】</li>
<li>当不同类型的数据进行运算时，表示范围大的类型转换成表示范围小的类型，称为【强制类型转换】</li>
<li>表达式<code>45 &amp; 20</code>的十进制值是【4】</li>
<li>表达式<code>1==1&gt;&gt;&gt;32</code>值为【true】</li>
</ol>

    </div>

    
    
    

    <footer class="post-footer">
          

<div class="post-copyright">
<ul>
  <li class="post-copyright-author">
      <strong>本文作者： </strong>William Leung
  </li>
  <li class="post-copyright-link">
      <strong>本文链接：</strong>
      <a href="https://gitee.com/lianghuilin/murmur.git/university_notes/Java(2)-%E6%95%B0%E6%8D%AE%E4%B8%8E%E8%A1%A8%E8%BE%BE%E5%BC%8F/" title="计应本的自考笔记(2)-Java数据与表达式">https://gitee.com/lianghuilin/murmur.git/university_notes/Java(2)-数据与表达式/</a>
  </li>
  <li class="post-copyright-license">
    <strong>版权声明： </strong>本博客所有文章除特别声明外，均采用 <a href="https://creativecommons.org/licenses/by-nc-sa/4.0/" rel="noopener" target="_blank"><i class="fab fa-fw fa-creative-commons"></i>BY-NC-SA</a> 许可协议。转载请注明出处！
  </li>
</ul>
</div>


        

          <div class="post-nav">
            <div class="post-nav-item">
                <a href="/murmur/university_notes/Java(1)-%E8%AF%AD%E8%A8%80%E6%A6%82%E8%BF%B0%E4%B8%8E%E7%8E%AF%E5%A2%83%E5%AE%89%E8%A3%85/" rel="prev" title="计应本的自考笔记(1)-Java语言概述与环境安装">
                  <i class="fa fa-chevron-left"></i> 计应本的自考笔记(1)-Java语言概述与环境安装
                </a>
            </div>
            <div class="post-nav-item">
                <a href="/murmur/university_notes/Java(3)-%E7%A8%8B%E5%BA%8F%E7%9A%84%E6%B5%81%E7%A8%8B%E6%8E%A7%E5%88%B6/" rel="next" title="计应本的自考笔记(3)-Java程序的流程控制">
                  计应本的自考笔记(3)-Java程序的流程控制 <i class="fa fa-chevron-right"></i>
                </a>
            </div>
          </div>
    </footer>
  </article>
</div>






      

<script>
  window.addEventListener('tabs:register', () => {
    let { activeClass } = CONFIG.comments;
    if (CONFIG.comments.storage) {
      activeClass = localStorage.getItem('comments_active') || activeClass;
    }
    if (activeClass) {
      const activeTab = document.querySelector(`a[href="#comment-${activeClass}"]`);
      if (activeTab) {
        activeTab.click();
      }
    }
  });
  if (CONFIG.comments.storage) {
    window.addEventListener('tabs:click', event => {
      if (!event.target.matches('.tabs-comment .tab-content .tab-pane')) return;
      const commentClass = event.target.classList[1];
      localStorage.setItem('comments_active', commentClass);
    });
  }
</script>

    </div>
  </main>

  <footer class="footer">
    <div class="footer-inner">
      

      

<div class="copyright">
  
  &copy; 
  <span itemprop="copyrightYear">2023</span>
  <span class="with-love">
    <i class="fa fa-heart"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">William Leung</span>
</div>
<div class="wordcount">
  <span class="post-meta-item">
    <span class="post-meta-item-icon">
      <i class="fa fa-chart-line"></i>
    </span>
    <span title="站点总字数">142k</span>
  </span>
  <span class="post-meta-item">
    <span class="post-meta-item-icon">
      <i class="fa fa-coffee"></i>
    </span>
    <span title="站点阅读时长">2:09</span>
  </span>
</div>
<div class="busuanzi-count">
    <span id="busuanzi_container_site_uv">
      本站访客数<span id="busuanzi_value_site_uv"></span>人次
    </span>
    <span id="busuanzi_container_site_pv">
        本站总访问量<span id="busuanzi_value_site_pv"></span>次
    </span>
</div>
  <div class="powered-by">由 <a href="https://hexo.io/" class="theme-link" rel="noopener" target="_blank">Hexo</a> & <a href="https://theme-next.js.org/" class="theme-link" rel="noopener" target="_blank">NexT.Gemini</a> 强力驱动
  </div>

    </div>
  </footer>

  
  <script src="//cdn.jsdelivr.net/npm/animejs@3.2.1/lib/anime.min.js"></script>
<script src="/murmur/js/utils.js"></script><script src="/murmur/js/motion.js"></script><script src="/murmur/js/next-boot.js"></script>

  
















  <script>
    NProgress.configure({
      showSpinner: true
    });
    NProgress.start();
    document.addEventListener('readystatechange', () => {
      if (document.readyState === 'interactive') {
        NProgress.inc(0.8);
      }
      if (document.readyState === 'complete') {
        NProgress.done();
      }
    });
    document.addEventListener('pjax:send', () => {
      NProgress.start();
    });
    document.addEventListener('pjax:success', () => {
      NProgress.done();
    });
  </script>


  
  <script async src="https://busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script>








  

  

</body>
</html>
